// Copyright (c) 2022 NetEase, Inc. All rights reserved.
// Use of this source code is governed by a MIT license that can be
// found in the LICENSE file.

import 'package:nim_core/nim_core.dart';
import 'package:hawk/hawk.dart';

import 'method_name_value.dart';

class HandleQuickCommentCase extends HandleBaseCase {
  HandleQuickCommentCase();

  @override
  Future<ResultBean?> handle(event) async {
    super.handle(event);
    var inputParams = Map<String, dynamic>();
    if (params != null && params!.length > 0) {
      inputParams = params![0] as Map<String, dynamic>;
    }

    switch (methodName) {
      case addQuickComment:
        {
          NIMResult<void> result = await NimCore.instance.messageService
              .addQuickComment(
                  NIMMessage.fromMap(inputParams['msg']),
                  inputParams['replyType'] as int,
                  inputParams['ext'] as String,
                  inputParams['needPush'] as bool? ?? false,
                  inputParams['needBadge'] as bool? ?? false,
                  inputParams['pushTitle'] as String,
                  inputParams['pushContent'] as String,
                  Map<String, Object>());
          handleCaseResult = ResultBean(
              code: result.code, data: result.toMap(), message: methodName);

          break;
        }
      case removeQuickComment:
        {
          final result = await NimCore.instance.messageService
              .removeQuickComment(
                  NIMMessage.fromMap(inputParams['msg']),
                  inputParams['replyType'] as int,
                  inputParams['ext'] as String,
                  inputParams['needPush'] as bool? ?? false,
                  inputParams['needBadge'] as bool? ?? false,
                  inputParams['pushTitle'] as String,
                  inputParams['pushContent'] as String,
                  Map<String, Object>());
          handleCaseResult = ResultBean(
              code: result.code, message: methodName, data: result.toMap());
          break;
        }
      case queryQuickComment:
        {
          var messageList = inputParams['msgList'] as List<dynamic>;
          List<NIMMessage> msgList =
              messageList.map((e) => NIMMessage.fromMap(e)).toList();
          final result =
              await NimCore.instance.messageService.queryQuickComment(msgList);
          handleCaseResult = ResultBean(
              code: result.code, message: methodName, data: result.toMap());

          break;
        }
    }
    return handleCaseResult;
  }
}
